#include <iostream>
#include <string>
#include <cmath>

bool isPrime(int num) {
    if (num <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string word1, word2, word3;
    int num1, num2, num3;
    
    std::cin >> word1 >> word2 >> word3;
    
    if (word1 == "zero") num1 = 0;
    else if (word1 == "one") num1 = 1;
    else if (word1 == "two") num1 = 2;
    else if (word1 == "three") num1 = 3;
    else if (word1 == "four") num1 = 4;
    else if (word1 == "five") num1 = 5;
    else if (word1 == "six") num1 = 6;
    else if (word1 == "seven") num1 = 7;
    else if (word1 == "eight") num1 = 8;
    else if (word1 == "nine") num1 = 9;
    else {
        std::cout << "wrong input";
        return 0;
    }
    
    if (word2 == "zero") num2 = 0;
    else if (word2 == "one") num2 = 1;
    else if (word2 == "two") num2 = 2;
    else if (word2 == "three") num2 = 3;
    else if (word2 == "four") num2 = 4;
    else if (word2 == "five") num2 = 5;
    else if (word2 == "six") num2 = 6;
    else if (word2 == "seven") num2 = 7;
    else if (word2 == "eight") num2 = 8;
    else if (word2 == "nine") num2 = 9;
    else {
        std::cout << "wrong input";
        return 0;
    }
    
    if (word3 == "zero") num3 = 0;
    else if (word3 == "one") num3 = 1;
    else if (word3 == "two") num3 = 2;
    else if (word3 == "three") num3 = 3;
    else if (word3 == "four") num3 = 4;
    else if (word3 == "five") num3 = 5;
    else if (word3 == "six") num3 = 6;
    else if (word3 == "seven") num3 = 7;
    else if (word3 == "eight") num3 = 8;
    else if (word3 == "nine") num3 = 9;
    else {
        std::cout << "wrong input";
        return 0;
    }
    
    int number = num1 * 100 + num2 * 10 + num3;
    
    while (true) {
        if (isPrime(number)) {
            std::cout << number;
            break;
        }
        number--;
    }
    
    return 0;
}
